* Model electoral choice
use querschnitt-2013.dta , replace 

* Keep pre-election data

keep if ! nachwahl

* Wahlentscheidung: grundsaetzlich muessen wir wenigstens von Wahl mit Sonstigen ausgehen
* Keep DKs, drop those who were not asked

drop if v11bb == .c | v11bb == .l

* Drop 'other' voters 

drop if v11bb >170 & v11bb <323
drop if v12bb >170 & v12bb <323

* use survey features

do survey-features.do

* reshape data for clogit
* Drop missings
drop if wahlfuenf == .

* parsimonious model
case2alt , choice(wahlfuenf) alt(altpi altcandidate altiddist) casevars(lire wilagut prosozialismus  gegenzuwanderung gerechtigkeitwichtig religpractice) altnum(partei) case(id)

lab var altpi "PI"
lab var altcandidate "Bewertung Kandidat"
lab var altiddist "Ideologische Distanz"

* Interactions: alternative-specific
	gen altpiXost = altpi * distostwest
	lab var altpiXost "PI X Ost"
	gen altcandidateXost = altcandidate * distostwest
	lab var altcandidateXost "Bewertung Kandidat X Ost"
	gen altiddistXost = altiddist* distostwest
	lab var altiddistXost "Ideologische Distanz X Ost"


* Parties
foreach p in Union SPD FDP B90Gruene Linke {
	gen `p'Xost = `p' * distostwest
	lab var `p'Xost "`p' X Ost"
* Party-specific effect of region 
* Socialism
	gen `p'XprosozialismusXost = `p'Xprosozialismus * distostwest
	lab var `p'Xprosozialismus "`p': Sozialismus gute Idee"
	lab var `p'XprosozialismusXost "`p': Sozialismus gute Idee X Ost"
* Immigration
	gen `p'XgegenzuwanderungXost = `p'Xgegenzuwanderung * distostwest
	lab var `p'Xgegenzuwanderung "`p': Ablehnung Zuwanderung"
	lab var `p'XgegenzuwanderungXost "`p': Ablehnung Zuwanderung X Ost"
* Church attendance
	gen `p'XreligpracticeXost = `p'Xreligpractice * distostwest
	lab var `p'Xreligpractice "`p': Religi�se Praxis"
	lab var `p'XreligpracticeXost "`p': Religi�se Praxis X Ost"
	}

* Simple model using SPD as baseline

local basevars " altpi altcandidate altiddist Union FDP B90Gruene Linke "
svy: clogit choice `basevars' , group(id)
est store b


* Plus some interactions

local einstellungen = " "
foreach e in prosozialismus gegenzuwanderung  {
	foreach p in Union FDP B90Gruene Linke {
		local einstellungen = "`einstellungen' `p'X`e' "
		}
	}

svy: clogit choice `basevars' `einstellungen' , group(id)
est store be

* Interaction: Party/base level
local partyinterceptinteractions = " "
foreach p in Union FDP B90Gruene Linke {
	loca partyinterceptinteractions = "`partyinterceptinteractions' `p'Xost "
	}

svy: clogit choice `basevars' `partyinterceptinteractions' `einstellungen' , group(id)
est store bpe


svy: clogit choice `basevars' `partyinterceptinteractions'  , group(id)
est store bp

local basevarsinteractions = " altpiXost altcandidateXost altiddistXost "



svy: clogit choice `basears'  `basevarsinteractions' `partyinterceptinteractions' `einstellungen' , group(id)
est store bbpe


local einstellungeninteractions = " "
foreach e in prosozialismus gegenzuwanderung  {
	foreach p in Union FDP B90Gruene Linke {
		local einstellungeninteractions = "`einstellungeninteractions' `p'X`e'Xost "
		}
	}

svy: clogit choice `basevars'  `basevarsinteractions' `partyinterceptinteractions' `einstellungen' `einstellungeninteractions' , group(id)
est store bbpee
* 


foreach m in b be bpe bp bbpe bbpee {
	est restore `m'
	display "Modell: `m'"
	getaicw 
	}


* bbpee  is best fit/complexity trade-off, bpe comes second

est restore be
getaicw
estadd scalar r(AICW)

est restore bpe
getaicw
estadd scalar r(AICW)

est restore bbpee
getaicw
estadd scalar r(AICW)


esttab be bpe bbpee , b(%9.1f) label nobaselevel nomtitle se  nodepvars interaction(" X ") varwidth(35) modelwidth(0) rename (_cons Konstante) stats(N AICW)

esttab be bpe bbpee using wahlentscheidung.rtf  , b(%9.1f) label nobaselevel nomtitle se  nodepvars interaction(" X ") varwidth(31) rename (_cons Konstante) stats(N AICW) rtf replace 

